package cn.itsource.basic.service.impl;

import cn.itsource.basic.mapper.BaseMapper;
import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.IBaseService;
import cn.itsource.basic.util.PageList;
import cn.itsource.order.domain.AdoptOrder;
import cn.itsource.order.query.AdoptOrderQuery;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T>{
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public void add(T t) {
        baseMapper.save(t);
    }
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.delete(id);
    }
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
    @Override
    public T findOne(Long id) {
        T t = (T)baseMapper.loadById(id);
        return t;
    }
    @Override
    public List<T> findAll() {
        List<T> list = baseMapper.loadAll();
        return list;
    }
    @Override
    public PageList<T> queryForPage(BaseQuery baseQuery) {
        //查询总数量
        Integer count = baseMapper.queryCount(baseQuery);
        if(count<=0){
            return new PageList<>();
        }
        //查询分页数据
        List<T> list = baseMapper.queryData(baseQuery);
        /*封装分页对象*/
        PageList<T> pageList = new PageList<>(count, list);
        return pageList;
    }

}
